<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="业务时间" prop="busitime">
      <el-input v-model="dataForm.busitime" placeholder="业务时间"></el-input>
    </el-form-item>
    <el-form-item label="业务发起标识:1-银行发起;2-登记中心发起" prop="inoutflag">
      <el-input v-model="dataForm.inoutflag" placeholder="业务发起标识:1-银行发起;2-登记中心发起"></el-input>
    </el-form-item>
    <el-form-item label="业务流水号:8位日期+2位机构号+8位序号" prop="busino">
      <el-input v-model="dataForm.busino" placeholder="业务流水号:8位日期+2位机构号+8位序号"></el-input>
    </el-form-item>
    <el-form-item label="登记中心机构编号" prop="bdcno">
      <el-input v-model="dataForm.bdcno" placeholder="登记中心机构编号"></el-input>
    </el-form-item>
    <el-form-item label="银行网点号" prop="obankid">
      <el-input v-model="dataForm.obankid" placeholder="银行网点号"></el-input>
    </el-form-item>
    <el-form-item label="银行行号" prop="bankid">
      <el-input v-model="dataForm.bankid" placeholder="银行行号"></el-input>
    </el-form-item>
    <el-form-item label="区划代码" prop="region">
      <el-input v-model="dataForm.region" placeholder="区划代码"></el-input>
    </el-form-item>
    <el-form-item label="交易代码" prop="msgtp">
      <el-input v-model="dataForm.msgtp" placeholder="交易代码"></el-input>
    </el-form-item>
    <el-form-item label="业务类型:1-登记;2-查询;3-注销;4-备案;5-电子下载;6-其他" prop="busitp">
      <el-input v-model="dataForm.busitp" placeholder="业务类型:1-登记;2-查询;3-注销;4-备案;5-电子下载;6-其他"></el-input>
    </el-form-item>
    <el-form-item label="业务标识码" prop="servicecode">
      <el-input v-model="dataForm.servicecode" placeholder="业务标识码"></el-input>
    </el-form-item>
    <el-form-item label="业务结果码" prop="status">
      <el-input v-model="dataForm.status" placeholder="业务结果码"></el-input>
    </el-form-item>
    <el-form-item label="业务结果描述" prop="descinfo">
      <el-input v-model="dataForm.descinfo" placeholder="业务结果描述"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          busitime: '',
          inoutflag: '',
          busino: '',
          bdcno: '',
          obankid: '',
          bankid: '',
          region: '',
          msgtp: '',
          busitp: '',
          servicecode: '',
          status: '',
          descinfo: '',
          remark: ''
        },
        dataRule: {
          busitime: [
            { required: true, message: '业务时间不能为空', trigger: 'blur' }
          ],
          inoutflag: [
            { required: true, message: '业务发起标识:1-银行发起;2-登记中心发起不能为空', trigger: 'blur' }
          ],
          busino: [
            { required: true, message: '业务流水号:8位日期+2位机构号+8位序号不能为空', trigger: 'blur' }
          ],
          bdcno: [
            { required: true, message: '登记中心机构编号不能为空', trigger: 'blur' }
          ],
          obankid: [
            { required: true, message: '银行网点号不能为空', trigger: 'blur' }
          ],
          bankid: [
            { required: true, message: '银行行号不能为空', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '区划代码不能为空', trigger: 'blur' }
          ],
          msgtp: [
            { required: true, message: '交易代码不能为空', trigger: 'blur' }
          ],
          busitp: [
            { required: true, message: '业务类型:1-登记;2-查询;3-注销;4-备案;5-电子下载;6-其他不能为空', trigger: 'blur' }
          ],
          servicecode: [
            { required: true, message: '业务标识码不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '业务结果码不能为空', trigger: 'blur' }
          ],
          descinfo: [
            { required: true, message: '业务结果描述不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcbusiness/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.busitime = data.bdcBusiness.busitime
                this.dataForm.inoutflag = data.bdcBusiness.inoutflag
                this.dataForm.busino = data.bdcBusiness.busino
                this.dataForm.bdcno = data.bdcBusiness.bdcno
                this.dataForm.obankid = data.bdcBusiness.obankid
                this.dataForm.bankid = data.bdcBusiness.bankid
                this.dataForm.region = data.bdcBusiness.region
                this.dataForm.msgtp = data.bdcBusiness.msgtp
                this.dataForm.busitp = data.bdcBusiness.busitp
                this.dataForm.servicecode = data.bdcBusiness.servicecode
                this.dataForm.status = data.bdcBusiness.status
                this.dataForm.descinfo = data.bdcBusiness.descinfo
                this.dataForm.remark = data.bdcBusiness.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcbusiness/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'busitime': this.dataForm.busitime,
                'inoutflag': this.dataForm.inoutflag,
                'busino': this.dataForm.busino,
                'bdcno': this.dataForm.bdcno,
                'obankid': this.dataForm.obankid,
                'bankid': this.dataForm.bankid,
                'region': this.dataForm.region,
                'msgtp': this.dataForm.msgtp,
                'busitp': this.dataForm.busitp,
                'servicecode': this.dataForm.servicecode,
                'status': this.dataForm.status,
                'descinfo': this.dataForm.descinfo,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
